//
//  HTVisitorViewController.swift
//  WeiBoDemo
//
//  Created by 郝涛 on 16/4/17.
//  Copyright © 2016年 郝涛. All rights reserved.
//

import UIKit


class HTVisitorViewController: UITableViewController {

    
    //定义bool值来判断展示是否登录
    let isLogin :Bool = HTUserAccountTools.sharedTools.isLogin
    
    //访客视图
    var visitorView :HTVisitorView?
    
    //控制器加载视图的方法
    override func loadView() {
        
        //判断是否是登录状态 显示不同的视图
        
                if isLogin{
                    super.loadView()
        
                }else{
                    setupVisitorView()
                    
                }

        
    }
    
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
    }
    //设置导航栏
    private func SetUpNav(){
        let leftItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
        
        navigationItem.leftBarButtonItem = leftItem
        let rightItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
        
        navigationItem.rightBarButtonItem = rightItem
        
    }
    
    //setupVisitorView 设置视图
    private func setupVisitorView(){
        SetUpNav()
        visitorView = HTVisitorView()
        //闭包
        visitorView?.ClickIncident = {
            
            self.loginClick()
        }
        //设置视图
        view = visitorView
        
    }
    //loginClick
    @objc private func loginClick(){
        //点击跳转
        let HTMicroblogLoginVC = HTMicroblogLoginController()
        
        presentViewController(UINavigationController(rootViewController: HTMicroblogLoginVC), animated: true, completion: nil)
    }
    
}
